<?php
namespace app\home\validate;

use think\Validate;

class Withdrawal extends Validate
{
    protected $rule = [
        'bank_id'                  => 'require|number|checkUserBank:bank_id',
        'put_money'                => 'require|number',
        'wallet_type'              => 'require|in:7,8',
        //'speed'                    => 'require|number|between:1,2',
    ];

    protected $message = [
        'bank_id.require'          => '请选择提现银行',
        'bank_id.number'           => '提现银行不正确',
        'bank_id.checkUserBank'    => '提现银行不正确',
        'put_money.require'        => '请输入提现金额',
        'put_money.number'         => '金额格式错误',
        'speed.require'            => '请选择提现方式',
        'speed.number'             => '提现方式不正确',
        'speed.between'            => '提现方式不正确',
        'wallet_type.require'      => '请选择钱包',
        'wallet_type.in'           => '钱包类型错误',
    ];
    /**
     * 提现银行判断
     * @param int       $bank_id     
     * @return bool
     */
    protected function checkUserBank($bank_id)
    {
        $uid = session('uid');
        $res =  db('bank')
                ->where("uid = $uid and status = 1 and id = $bank_id")
                ->find();
        if ($res) {                 // 查询结果
            return true;
        }else{
            return false;
        }
    }
}